﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace RimZombieGirl
{
    class HediffComp_WormMother : HediffComp
    {
        private int curTick;
        public HediffCompProperties_WormMother Props
        {
            get
            {
                return (HediffCompProperties_WormMother)this.props;
            }
        }
        public override void CompPostMake()
        {
            base.CompPostMake();
            if (Props.onceCount == default || Props.onceTime == default || Props.pawnKindDef == default)
            {
                Log.Warning("RimZombieGirl -> HediffComp_WormMother -> onceCount or onceTime or pawnKindDef is default");
            }
            curTick = 0;
        }

        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);
            if (curTick >= Props.onceTime)
            {
                curTick = 0;
                Faction faction = parent.pawn.Faction;
                for (int i = 0; i < Props.onceCount; i++)
                {
                    Pawn gemPawm = PawnGenerator.GeneratePawn(PawnKindDef.Named(Props.pawnKindDef.defName), faction != default ? faction : Find.FactionManager.FirstFactionOfDef(Props.pawnKindDef.defaultFactionDef));
                    GenSpawn.Spawn(gemPawm, parent.pawn.Position, parent.pawn.Map, WipeMode.VanishOrMoveAside);
                }
            }
            curTick++;
        }
    }
}
